package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;


/**
 * 空间的点
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexXYZPointDenote extends LatexGeometryDenote {
    /**
     * X轴坐标
     */
    private BigDecimal xValue;

    /**
     * Y轴坐标
     */
    private BigDecimal yValue;

    /**
     * Z轴坐标
     */
    private BigDecimal zValue;

    public String getLatex() {
        return "\\left(" + xValue + "," + yValue + "," + zValue + "\\right)";
    }

    public LatexXYZPointDenote(BigDecimal xValue, BigDecimal yValue, BigDecimal zValue) {
        this.xValue = xValue;
        this.yValue = yValue;
        this.zValue = zValue;
    }

    public LatexXYZPointDenote(String xValueText, String yValueText, String zValueText) {
        xValueText = xValueText.replace("\\left(", "").replace("(", "");
        zValueText = zValueText.replace("\\right)", "").replace(")", "");

        this.xValue = ParseHelper.parseBigDecimal(xValueText);
        this.yValue = ParseHelper.parseBigDecimal(yValueText);
        this.zValue = ParseHelper.parseBigDecimal(zValueText);
    }

    public LatexXYZPointDenote(String content) {
        var text = content.replace("\\left", "").replace("\\right", "");
        text = text.replace("(", "").replace(")", "");
        var array = text.split(",");
        if (array.length == 3) {
            this.xValue = ParseHelper.parseBigDecimal(array[0]);
            this.yValue = ParseHelper.parseBigDecimal(array[1]);
            this.zValue = ParseHelper.parseBigDecimal(array[2]);
        }
    }
}
